<template>
	<view class="box">
		<view class="top_kong"></view>
		<view class="center">
			<view class="pay_title">
				<view class="pay_line"></view>
				课程基本信息
			</view>
			<block v-if='categorytype == 3'>
				<!-- 渲染助攻 -->
				<view class="center_list flexs2">
					<image class="center_image" :src="picture.getImgUrl(InfoList.image)" mode=""></image>
					<view class="center_right">
						<view class="top_titles">
							{{InfoList.name}}
						</view>
						<view class="flexs2">
							<view class="flexs1">
								<view class="cemter_last"><text class="fwt">￥</text>{{InfoList.price}}</view>
								<view class="nub_hui"></view>
								<!-- ￥{{InfoList.original_price}} -->
							</view>
							<view class="vipmo">
								VIP:￥{{InfoList.discount_price}}
							</view>
						</view>
					</view>
				</view>
			</block>
			<block v-if='categorytype == 1'>
				<!-- 渲染课程 -->
				<view class="center_list flexs2">
					<image class="center_image" :src="picture.getImgUrl(kechengList.image)" mode=""></image>
					<view class="center_right">
						<view class="top_titles">
							{{kechengList.name}}
						</view>
						<view class="flexs2">
							<view class="flexs1">
								<view class="cemter_last"><text class="fwt">￥</text>{{kechengList.now_price}}</view>
								<view class="nub_hui">￥{{kechengList.original_price}}</view>
							</view>
							<view class="vipmo">
								VIP:￥{{kechengList.discount_price}}
							</view>
						</view>
					</view>
				</view>
			</block>
			<block v-if='categorytype == 2'>
				<!-- 渲染试题 -->
				<view class="center_list flexs2">
					<image class="center_image" src="../../static/image/sy_img_bskc@2x.png" mode=""></image>
					<view class="center_right">
						<view class="top_titles">
							{{kechengList.name}}
						</view>
						<view class="flexs2">
							<view class="flexs1">
								<view class="cemter_last"><text class="fwt">￥</text>{{kechengList.now_price}}</view>
								<view class="nub_hui">￥{{kechengList.original_price}}</view>
							</view>
							<view class="vipmo">
								VIP:￥{{kechengList.discount_price}}
							</view>
						</view>
					</view>
				</view>
			</block>
		</view>
		
		<paymantcom :type="type"  @selectchoose ='selectchoose' @selecttomima = 'selecttomima'></paymantcom>
		<!-- 支付密码 -->
		<passkeyborad :show="show" @close="close" @makesure="makesure"></passkeyborad>
	</view>
</template>
<script>
	import {Detail,Curriculumdetail,OrderPay,headlook,experience} from '@/api/personal.js';
	import paymantcom  from '../../components/payment-com.vue';
	import passkeyborad from '../../components/yzc-paykeyboard/yzc-paykeyboard.vue';
	export default {
		components: {
			passkeyborad,
			paymantcom
		},
		data() {
			return {
				type: 1,
				// show: false,
				show:{showStatus:false},
				ordernumber: '',
				paymoney: '',
				pagetype: '',
				orderid:'',
				categorytype:'',
				id:'',
				InfoList:'',//助攻
				kechengList:'',//课程
				pay_pwd:''
			}
		},
		onLoad(option) {
			this.orderid = option.orderid
			this.categorytype =option.type
			this.id = option.id
			if(this.categorytype == 1||this.categorytype==2){
				// 课程详情
				this.getkechengList()
			}else if(this.categorytype == 3){
				// 请求助攻详情
				this.getInfoList()
			}else{
				// 试题详情
			}
		},
		onShow() {
			this.getInfo()
		},
		methods: {
			getInfoList(){
				var obj = {
					a_id:this.id
				};
				Detail(obj).then(res => {
					if (res.code == 1) {
						this.InfoList = res.data
					}
				})
			},
			getkechengList(){
				var obj = {
					c_id:this.id
				};
				Curriculumdetail(obj).then(res => {
					if (res.code == 1) {
						this.kechengList = res.data
					}
				})
			},
			makesure(e) {
				console.log(e)//支付密码
				this.show.showStatus=false
				let obj = {
					o_id:this.orderid,
					pay_pwd:e
				}
				OrderPay(obj).then(res=>{
					console.log(res)
					if(res.code == 1){
						uni.navigateTo({
							url: "paysuccess?type="+this.categorytype
						})
					}else{
						this.$msg(res.msg)
					}
				})
			},
			goback() {
				uni.navigateBack({
					delta: 1
				})
			},
			selectchoose(val) {
				// val:0余额,1微信,2支付宝
				this.type = val
				console.log(this.type);
			},
			
			close() {
				this.show.showStatus=false
			},
			getInfo(){
				var obj = {
				};
				headlook(obj).then(res => {
					if (res.code == 1) {
						this.pay_pwd=res.data.pay_pwd
					}
				})
			},
			selecttomima(){
				this.type == 0 ? this.tomima(): this.goPay(this.categorytype)
			},
			tomima() {
				if(this.pay_pwd==null){
					this.$msg('请设置余额支付密码')
				}else{
					this.show.showStatus= true
				}	
			},
			goPay(mtype){
				console.log(this.type);
				var type = ''
				var provider = ''
				if(this.type == 1){
					type = 'wechat'
					provider = 'wxpay'
				}else{
					type = 'alipay'
					provider = 'alipay'
				}
				var obj = {
					o_id:this.orderid,
					type,
					method:'app'
				};
				experience(obj).then(res => {
						if(res.code==0){
							this.$msg(res.msg);
						}else{
							console.log(res.data,'5555')
							console.log(this.id,'9998')
							uni.requestPayment({
									provider: provider,
							        orderInfo: JSON.stringify(res), 
							        success: function (res) {
							            console.log('success:' + JSON.stringify(res));
										uni.navigateTo({
											url: "paysuccess?type="+mtype
										})
							        },
							        fail: function (err) {
							            console.log('fail:' + JSON.stringify(err));
							        }
							    });
								
						}
					})
			}


		}
	}
</script>

<style>
	.box {
		width: 100%;
		height: 100%;
		/* background-color: #F5F5F5; */
	}



	/* cemter */
	.center {
		width: 100%;
		height: auto;
		padding: 10rpx 30rpx;
		background-color: #FFFFFF;
	}

	.vipmo {
		width: auto;
		line-height: 40rpx;
		background: #FFE7E6;
		border-radius: 6rpx;
		font-size: 26rpx;
		color: #FF3B30;
		padding: 0 10rpx;
		margin-right: 10rpx;
	}

	.center_pay {
		font-size: 22rpx;
		color: #999999;
	}

	.cemter_last {
		height: 40rpx;
		font-size: 34rpx;
		color: #FF3B30;
		font-weight: bold;
	}

	.center_study {
		margin-top: 6rpx;
		color: #666666;
		font-size: 24rpx;
	}

	.center_right {
		width: 475rpx;
		height: auto;
		padding: 20rpx 0 0 0;
	}

	.top_titles {
		width: 458rpx;
		height: 90rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		line-height: 42rpx;
		color: #333333;
		font-size: 28rpx;
		max-height: 90rpx;
		overflow: hidden;
		word-break: break-all;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}

	.center_image {
		width: 196rpx;
		height: 130rpx;
		border-radius: 10rpx;

	}

	.fwt {
		font-size: 24rpx;
	}

	.top_kong {
		width: 100%;
		height: 20rpx;
		background-color: #F5F5F5;
	}

	.nub_hui {
		height: 30rpx;
		font-size: 20rpx;
		color: #999999;
		margin-left: 6rpx;
		text-decoration: line-through;
	}

	.top-kong {
		width: 100%;
		height: var(--status-bar-height);
		background-color: #FFFFFF;
	}

	.border {
		width: 100%;
		height: 100rpx;
		padding: 0 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #FFFFFF;
	}

	.border image {
		width: 20rpx;
		height: 36rpx;
	}

	.border_start {
		display: flex;
		align-items: center;
	}

	.border_title {
		font-size: 34rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #303030;
	}

	.border_end {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
		text-align: end;
	}

	.border_end image {
		width: 33rpx;
		height: 36rpx;
	}

	.item_box {
		width: 100%;
		height: 700rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		margin: 0 auto;
		overflow: hidden;
	}

	.top_item {
		width: 100%;
		height: 300rpx;
		color: #FF4145;
		font-size: 72rpx;
		background-color: #F5F5F5;
		text-align: center;
		padding: 80rpx;
	}

	.top_price {
		font-size: 72rpx;
		font-weight: bold;
		color: #FF4145;
	}

	.top_ordernum {
		font-size: 24rpx;
		color: #333333;
	}
	
	.btns {
		width: 86%;
		height: 88rpx;
		background: #FFDD47;
		border-radius: 10rpx;
		margin: 80rpx auto 0;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 30rpx;
		color: #333333;
		position: absolute;
		bottom: 3%;
		left: 6.7%;
	}

</style>
